﻿@{
    ViewBag.Title = "AddBanner";
    Layout = "~/Areas/AdminInfo/Views/Shared/_LayoutPage1.cshtml";
}
@model Gtkj.CMS.Model.Banner
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <section class="panel panel-padding">

                    <form id="form1" class="layui-form layui-form-pane" data-render="true">
                        <div class="layui-form-item">
                            <label class="layui-form-label">连接</label>
                            <div class="layui-input-block">
                                <input type="text" name="BannerURL" value="@(Model==null?"": Model.BannerURL)" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">上传图片</label>
                            <div class="layui-input-inline">
                                <input type="file" name="Logo" class="layui-upload-file">
                                <input type="hidden" name="Image" id="imgsrc" value="@(Model == null ? "" : Model.Image)">
                                <p id="img-error" class="error">
                                    @{
                                        if (Model != null)
                                        {
                                            if (Model.Image != null || Model.Image != "")
                                            {
                                                <img src="@Model.Image" alt="..." class="img-thumbnail">
                                            }
                                        }
                                    }
                                </p>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">分类</label>
                            <div class="layui-input-inline">
                                <select name="TypeID" id="TypeID" jq-verify="required" jq-error="请输入分类" lay-filter="verify">
                                    <option value="">请选择</option>
                                    <option value="1">背景图</option>
                                    <option value="2">合作伙伴</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item ">
                            <label class="layui-form-label">排名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="Sorting" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" required jq-verify="number" value="@(Model == null ? 0 : Model.Sorting == null ? 0 : Model.Sorting)" jq-error="排名必须为数字" placeholder="请输入排名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                                @if (Model == null)
                                {
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                }
                            </div>
                        </div>
                        <input type="hidden" name="ID" value="@(Model==null?"":Model.ID.ToString())" /> />
                    </form>
                </section>
            </div>
        </div>
    </div>

<script>
    var $;
    //var $Type = $("Type");
    layui.use(['form', 'upload', 'jqform'], function () {
        var editIndex;
        $ = layui.jquery,
            jqform = layui.jqform,
         form = layui.form(), layedit = layui.layedit;
       
        $("#TypeID").val(@(Model ==null?"":Model.Type.ToString()));
        form.render(); //这个很重要
        layui.upload({
            url: '/Upload/UploadPic' //上传接口file1
         , success: function (res) { //上传成功后的回调
             console.log(res);
             $('#img-error').html("");
             $('#imgsrc').val(res.data);
             $('#img-error').append('<img src="' + res.data + '" alt="..." class="img-thumbnail">');
         }
        });

        form.on('submit(sub)', function (data) {
            //layedit.getContent(index)
            //$('#LAY_demo_editor').val(layedit.getContent(editIndex));
            $.post('/AdminInfo/AdminSystem/AddBannerInfo', data.field, function (r) {
                if (r.status == 200) {
                    layer.msg(r.message, {
                        icon: 6,
                        time: 2000,
                    });
                } else {
                    layer.msg(r.message, { icon: 2 });
                }
            });
            return false;
        });
    });
</script>